package com.example.interview.ch02;

import java.util.concurrent.locks.LockSupport;

/**
 * 交替输出问题
 *
 * @author anin
 * @date 2022/3/22 9:49 AM
 */
public class Test2 {
    static Thread t1, t2 = null;

    public static void main(String[] args) {

        char[] c1 = "AAAAAAAAAAA".toCharArray();
        char[] c2 = "111111111".toCharArray();

        t1 = new Thread(() -> {
            for (char c : c1) {
                System.out.println(c);
                t2.notify();
                try {
                    t1.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }, "t1");

        t2 = new Thread(() -> {
            for (char c : c2) {
                System.out.println(c);
                t1.notify();
                try {
                    t2.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }, "t2");

        t1.start();
        t2.start();
    }
}
